<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Vue.js字符跑马灯</title>
    <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
    <style>
        /* 隐藏未编译的变量 */

        [v-cloak] {
            display: none;
        }

        * {
            margin: 0;
            padding: 0;
        }

        body {
            text-align: center;
        }

        div {
            position: absolute;
            left: 50%;
            top: 30%;
            -webkit-transform: translate(50%, 50%);
            transform: translate(-50%, -50%);
        }

        div p {
            font-size: 24px;
            color: rgb(52, 210, 250);
            font-weight: normal;
            font-family: cursive;
        }
    </style>
</head>

<body>
    <div id="main" v-cloak>
        <p v-on:mouseover="run()" v-on:mouseleave="stop()">{{turn_text}}</p>
    </div>
    <script>
        var demo = new Vue({
            el: "#main",
            data: {
                turn_text: "鼠标移动到这里，文字会动起来哦！",
                interval: null
            },
            methods: {
                run() {
                    //每隔250ms执行一次function里面的操作
                    interval = setInterval(function () {
                        //截取turn_text的第一个字符
                        var start = demo.turn_text.substring(0, 1);
                        //截取turn_text从第二个开始到最后的字符
                        var end = demo.turn_text.substring(1);
                        demo.turn_text = end + start;
                    }, 250)
                },
                stop() {
                    clearInterval(interval);
                }
            }
        })
    </script>
</body>

</html>